package team.com;

import org.anddev.andengine.audio.music.Music;
import org.anddev.andengine.audio.music.MusicFactory;
import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.BoundCamera;
import org.anddev.andengine.opengl.texture.BuildableTexture;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TextureRegionFactory;

import android.view.TextureView;

public class ResourcesManager {
	
	private Music musicBackground;

	private Texture _splash;
	public TextureRegion _splashR;
	private Texture _player;
	public TextureRegion _playerRegion;
	
	// Menu
	
	public TextureRegion menu_backgound_region;
	public TextureRegion play_region;
	public TextureRegion options_region;
	//private BuildableTexture menuTexture;
	private Texture menuTexture;
	private Texture play;
	private Texture options;
	
	
	private static final ResourcesManager INSTANCE = new ResourcesManager();
	public Engine engine;
	public MainActivity activity;
	public BoundCamera camera;
	
	public void loadMenuResources()
	{
		loadMenuGraphics();
		loadMenuAudio();
	}
	
	private void loadMenuAudio() {
		// TODO Auto-generated method stub
		//musicBackground = MusicFactory.createMusicFromAsset(this.engine.getMusicManager(), this, pAssetPath)
	}

	private void loadMenuGraphics() {
		// TODO Auto-generated method stub
		
		TextureRegionFactory.setAssetBasePath("gfx/");
		menuTexture = new Texture(1024, 1024,TextureOptions.DEFAULT);
		menu_backgound_region = TextureRegionFactory.createFromAsset(menuTexture,activity,"splash.png",0,0);
		play_region = TextureRegionFactory.createFromAsset(menuTexture, activity, "play.png",500,0);
		options_region = TextureRegionFactory.createFromAsset(menuTexture, activity, "options.png",601,0);
		engine.getTextureManager().loadTexture(menuTexture);		
	}
	
	public void loadGameResources()
	{
		loadGameGraphics();
		loadGameAudio();
		loadGameFonts();
	}

	private void loadGameFonts() {
		// TODO Auto-generated method stub
		
	}

	private void loadGameAudio() {
		// TODO Auto-generated method stub
		
	}

	private void loadGameGraphics() {
		
		TextureRegionFactory.setAssetBasePath("gfx/");
		_player = new Texture(32, 32, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		_playerRegion = TextureRegionFactory.createFromAsset(_player, activity, "box.png", 0, 0);
	}
	
	public void loadSplashScene()
	{
		TextureRegionFactory.setAssetBasePath("gfx/");
		_splash = new Texture(512, 512, TextureOptions.DEFAULT);
		_splashR = TextureRegionFactory.createFromAsset(_splash, activity, "splash.png", 0, 0);
		engine.getTextureManager().loadTexture(_splash);
	}
	
	public void unLoadSplashScene()
	{
		_splash.unloadFromHardware(null);
		_splashR = null;
	}
	
	public static void prepairManager(Engine e, MainActivity mActivity, BoundCamera cam)
	{
		getInstance().engine = e;
		getInstance().activity = mActivity;
		getInstance().camera = cam;
	}
	
	public static ResourcesManager getInstance()
    {
        return INSTANCE;
    }
}
